package cn.tansanqinger.dao.sql.topic;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import cn.tansanqinger.dao.sql.IRecordTopicSqlDao;
import cn.tansanqinger.pojo.Recordtopic;

@Repository
public class RecordtopicSqlDaoImpl {

	@Autowired
	private IRecordTopicSqlDao dao;
	
	/**
	 * 随机读取一条数据
	 * @return
	 */
	public List<Recordtopic> selectTopic(int ttype, int source, int difficulty, int classify, int grade) {
		QueryWrapper<Recordtopic> queryWrapper = new QueryWrapper<Recordtopic>();
		if(ttype!=-1) queryWrapper.lambda().eq(Recordtopic::getTtype, ttype);
		if(difficulty!=-1) queryWrapper.lambda().eq(Recordtopic::getTdifficulty, difficulty);
		if(classify!=-1) queryWrapper.lambda().eq(Recordtopic::getTclassify, classify);
		if(grade!=-1) queryWrapper.lambda().eq(Recordtopic::getTgrade, grade);
		if(source==0||source==1) {
			queryWrapper.lambda().eq(Recordtopic::getRresult, 1);
		}
		return dao.selectList(queryWrapper);
	}
	
	/**
	 * 添加信息
	 * @param course
	 * @return
	 */
	public int add(Recordtopic object) {
		return dao.insert(object);
	}
	
	/**
	 * 查询信息
	 * @param cid
	 * @return
	 */
	public Recordtopic selectOnt(int id) {
		return dao.selectById(id);
	}
	
	/**
	 * 根据条件查询数据
	 * @param id1
	 * @param id2
	 * @return
	 */
	public Recordtopic selectId(int id1 , int id2) {
		QueryWrapper<Recordtopic> queryWrapper = new QueryWrapper<Recordtopic>();
		queryWrapper.lambda().eq(Recordtopic::getTid, id1).eq(Recordtopic::getUid, id2);
		return dao.selectOne(queryWrapper);
	}
	
	/**
	 * 修改信息
	 * @param user
	 * @return
	 */
	public int modification(Recordtopic object) {
		return dao.updateById(object);
	}
}
